<?php

// $Id: vpage_news_list_form_ajax_ctrl.class.php 1570 2009-01-13 12:44:02Z ogrebg $

require_once(TANGRA_MAIN_DIR.'web_site/web_page/just_headers_view.class.php');

require_once($WSC->get_site_inc_dir().'modules/admin_panel/site_admin_ajax_form_ctrl_with_object_ua.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/vpage/tcms_vpage_dbc.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/forms/_vpt/vpage_news_list/vpage_news_list_form_ctrl.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/tcms_ci_type_attr_dbc.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/tcms_ci_type_dbc.class.php');


class VPage_News_List_Form_Ajax_Ctrl extends Site_Admin_Ajax_Form_Ctrl_With_Object_UA {
	protected function init_transit_vars() {
		$this->add_transit_var('category');
		$this->add_transit_var('vpage');
	}


	public function run() {
		parent::run();
		$current_user = $this->get_user();
		$this->form_ctrl->set_permanent_external_param('user_id', $current_user->get_id());
	}


	protected function on_good_submit() {
		$object = $this->form_ctrl->get_object();

		$params_arr = array('manage' => $object->get_id());
		$redir = $this->create_redirect_composer('admin/modules/tangra_cms/vpt/news_list/vpage_man_news_list.php', $params_arr);

		$location = $redir->get_target_address();

		$ret = array('command' => Ajax_Ctrl::COMMAND_REDIRECT, 'command_value' => $location);

		return $ret;
	}


	protected function on_bad_submit() {
		$object = $this->form_ctrl->get_object();

		$vpage = new TCMS_VPage_DBC();
		$dbc = $this->get_dbc();
		if ($vpage->load_by_id($dbc, $object->get_id())) {
			$this->export('vpage', $vpage);
		} else {
			throw new Tangra_Module_Exception('Cannot load vpage with id = '.$object_id);
		}


		return true;
	}


	protected function create_form_ctrl() {
		$tvm = $this->get_tvm();
		$dbc = $this->get_dbc();

		$ret = new VPage_News_List_Form_Ctrl('vpage', $tvm, $dbc);

		return $ret;
	}
}